package com.qfedu.cardlikeboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.cardlikeboot.domain.Card;
import com.qfedu.cardlikeboot.mapper.CardMapper;
import com.qfedu.cardlikeboot.service.CardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @auther asus
 * @date 2022/5/18 20:42
 */
@Service
public class CardServiceImpl implements CardService {

    @Resource
    CardMapper cardMapper;

    //新增名片
    @Override
    public Integer addCard(Card card) {
        int i = cardMapper.insertSelective(card);
        return i;
    }

    //分页查看名片列表
    @Override
    public PageInfo<Card> selectCardByPage(Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Card> cards=cardMapper.selectAll();
        PageInfo<Card> cardPageInfo = new PageInfo<>(cards);
        return cardPageInfo;
    }

    //查看名片
    @Override
    public Card selectCardById(Integer id) {
        Card card = cardMapper.selectByPrimaryKey(Long.valueOf(id));
        card.setVisited(card.getVisited()+1);
        cardMapper.updateByPrimaryKeySelective(card);
        return card;
    }
}
